#!/bin/bash
# set -x
# define vars

read -p "请选择部署集群的网络插件[calico|cilium|flannel|weave]: " network_plugin

folder=`echo $RANDOM`

clean_script_dir=clean
clean_script_file=${clean_script_dir}/clean-openstack-$network_plugin-$folder.sh
deploy_script_dir=deploy
deploy_script_file=${deploy_script_dir}/deploy_cluster_openstack_${network_plugin}_$folder.sh

# create project
cp -a /root/kubernetes_deploy/inventory/mycluster-openstack-14286 /root/kubernetes_deploy/inventory/mycluster-openstack-$network_plugin-$folder

# create inventory

CONFIG_FILE=./inventory/mycluster-openstack-$network_plugin-$folder/hosts.yaml python3 contrib/inventory_builder/inventory.py $@

# create clean script
cat>$clean_script_file<<EOF
#!/bin/bash
ansible-playbook -i ../inventory/mycluster-openstack-$network_plugin-$folder/hosts.yaml  --become --become-user=root ../reset.yml \$@
EOF

# add exec permission to clean script
chmod +x $clean_script_file

# create deployment script
cat >$deploy_script_file<<EOF
#!/bin/bash
ansible-playbook -i ../inventory/mycluster-openstack-$network_plugin-$folder/hosts.yaml  --become --become-user=root ../cluster.yml \$@
EOF

# add exec permission to deploy script
chmod +x $deploy_script_file

echo -e "\n"

echo -e "清理环境脚本：$clean_script_file"
echo -e "部署集群脚本：$deploy_script_file"

